/*
#include <motor_task.h>
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-03-07     Hao       the first version
 */
#include "app_main.h"

#include "motor_task.h"
#include "can_upper_task.h"

// 任务结构体
typedef struct _task
{
    rt_thread_t tid;
    const char *name;
    void (*entry)(void *param);
    void *param;
    rt_uint32_t stack_size;
    rt_uint8_t  priority;
    rt_uint32_t tick;
}task_t;
typedef task_t *task_ptr;

// 任务列表
task_t tasks[] =
{
    {RT_NULL, "motor_task",         motor_task,         RT_NULL, 512, 22, 5},  // 要比SHELL优先级低，方便用SHELL命令调节PID
    {RT_NULL, "can_upper_task",     can_upper_task,     RT_NULL, 512, 21, 5},
};

// 启动所有线程
void user_main()
{
    // 启动任务
    for(uint8_t i = 0; i < (sizeof(tasks)/sizeof(task_t)); i++)
    {
        tasks[i].tid = rt_thread_create(tasks[i].name,
                                        tasks[i].entry,
                                        tasks[i].param,
                                        tasks[i].stack_size,
                                        tasks[i].priority,
                                        tasks[i].tick);

        if (tasks[i].tid != RT_NULL)
        {
            rt_thread_startup(tasks[i].tid);
        }
        else
        {
            rt_kprintf("%s create failed!\n", tasks[i].name);
        }
    }
}
